

#include <iostream>

#include <gtest/gtest.h>

#include "Utility/Exception/SGException.h"

using SG::Utility::SGException;

TEST (SGExceptionTest, PrintMethod)
{
    try
    {
        std::ostringstream       oss;
        SG::Utility::SGException sgException ("Print test message");
        sgException.print (oss);
        throw sgException;
    }
    catch (const SG::Utility::SGException& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Print test message"));
    }
}

TEST (SGRuntimeErrorTest, PrintMethod)
{
    try
    {
        std::ostringstream          oss;
        SG::Utility::RuntimeError sgRuntimeError ("Print test message");
        sgRuntimeError.print (oss);
        throw sgRuntimeError;
    }
    catch (const SG::Utility::RuntimeError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Print test message"));
    }
}

TEST (TypeErrorTest, PrintMethod)
{
    try
    {
        std::ostringstream     oss;
        SG::Utility::TypeError typeError ("Print test message");
        typeError.print (oss);
        throw typeError;
    }
    catch (const SG::Utility::TypeError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Print test message"));
    }
}

TEST (ValueErrorTest, PrintMethod)
{
    try
    {
        std::ostringstream      oss;
        SG::Utility::ValueError valueError ("Print test message");
        valueError.print (oss);
        throw valueError;
    }
    catch (const SG::Utility::ValueError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Print test message"));
    }
}

TEST (IndexErrorTest, PrintMethod)
{
    testing::internal::CaptureStdout ();
    SG::Utility::IndexError error ("Print test");
    error.print (std::cout);
    std::string output = testing::internal::GetCapturedStdout ();
    EXPECT_NE (std::string::npos, output.find ("Print test"));
}

TEST (ImportErrorTest, PrintMethod)
{
    try
    {
        const char*              msg = "Test error message";
        SG::Utility::ImportError err (msg);
        std::ostringstream       oss;
        err.print (oss);
        throw err;
    }
    catch (const SG::Utility::ImportError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Test error message"));
    }
}

TEST (ParserErrorTest, PrintMethod)
{
    try
    {
        std::ostringstream       oss;
        SG::Utility::ParserError pe ("Test error message");
        pe.print (oss);
        throw pe;
    }
    catch (const SG::Utility::ParserError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Test error message"));
    }
}

TEST (FileSystemError, PrintMethod)
{
    try
    {
        std::ostringstream           oss;
        SG::Utility::FileSystemError fileSystemError ("Test error message");
        fileSystemError.print (oss);
        throw fileSystemError;
    }
    catch (const SG::Utility::FileSystemError& e)
    {
        std::cout << e.what ();
        EXPECT_NE (std::string::npos, std::string (e.what ()).find ("Test error message"));
    }
}